package com.z.admin.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("admin")
public class AdminController {

    @PreAuthorize("hasAuthority('sys:admin')")
    @GetMapping({"/", "index"})
    public String index(Model model) {
        boolean isLogin = false;
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (!(authentication instanceof AnonymousAuthenticationToken)) {
            isLogin = true;
        }
        model.addAttribute("isLogin", isLogin);
        return "admin/index";
    }
    @GetMapping("welcome")
    public String welcome(Model model) {
        return "admin/welcome";
    }
}
